package chapter01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * yield 让出cup使用权，进入就绪状态
 */
@Slf4j
public class YeildTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            int a=1;
            while (true){
                try {
//                    Thread.sleep(50);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                log.info("t1:{}",a++);
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            int a=1;
            while (true){
                try {
                    Thread.yield();
//                    Thread.sleep(50);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                log.info("t2:{}",a++);
            }
        }, "t2");
        t1.setPriority(1);
        t2.setPriority(10);
        t1.start();
        t2.start();
    }
}
